﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace BusinessClass
{
    public static class FileHelper
    {
        /// <summary>
        /// 移动文件夹中文件。返回移动后文件路径集合。
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="targetDir"></param>
        /// <returns></returns>
        public static IEnumerable<string> MoveDirFiles(string dir, string targetDir)
        {
            var files = Directory.GetFiles(dir);
            return
                files.Select(
                  file =>
                  {
                      var name = Common.getFileName(file);
                      var targetFilename = Common.conbindPath(targetDir, name);
                      File.Copy(file, targetFilename, true);
                      return targetFilename;
                  }).ToList();
        }
        public static void NewName(this string orgFileFullPath, string newName)
        {
            File.Move(orgFileFullPath, Common.conbindPath(Common.getDir(orgFileFullPath), newName));
        }
        public static void DeleteTempFile(IEnumerable<string> files)
        {
            foreach (var file in files)
            {
                File.Delete(file);
            }
        }
    }
}
